package main

import (
	"gitee.com/goblog2/bootstrap"
	"gitee.com/goblog2/pkg"
	"net/http"
)

type App struct{ *pkg.App }

func (a *App) run() {
	err := http.ListenAndServe(":4000", a.Router)
	if err != nil {
		panic(err)
	}
}

func main() {
	pkg.GlobalApp = pkg.App{
		Router: bootstrap.InitRouter(),
		DB:     bootstrap.ConnectDB(),
	}
	app := App{&pkg.GlobalApp}
	app.run()
}

//
//var router = mux.NewRouter().StrictSlash(true)
//var db *sql.DB
//var tmplDir = "resources/compiled_views/"

//	func (a Article) Link() string {
//		url, _ := router.Get("articles.show").URL("id", strconv.FormatInt(a.ID, 10))
//		return url.String()
//	}

//
//func articlesDestroyHandler(w http.ResponseWriter, r *http.Request) {
//	vars := mux.Vars(r)
//	id := vars["id"]
//	sql := "delete from articles where id=?"
//	stmt, err := db.Prepare(sql)
//	checkError(err)
//	defer stmt.Close()
//	result, err2 := stmt.Exec(id)
//	checkError(err2)
//	rowsAffected, _ := result.RowsAffected()
//	if rowsAffected > 0 {
//		index, _ := router.Get("articles.index").URL()
//		http.Redirect(w, r, index.Path, http.StatusFound)
//	} else {
//		router.NotFoundHandler.ServeHTTP(w, r)
//	}
//}
//
//func articlesUpdateHandler(w http.ResponseWriter, r *http.Request) {
//	vars := mux.Vars(r)
//	id := vars["id"]
//	// 更新整个资源的逻辑
//
//	w.WriteHeader(http.StatusOK)
//	w.Write([]byte("Updated (PUT) resource " + id))
//}
//
//func articlesEditHandler(w http.ResponseWriter, r *http.Request) {
//	vars := mux.Vars(r)
//	id := vars["id"]
//	article := Article{}
//	err := db.QueryRow("select * from articles where id=?", id).Scan(&article.ID, &article.Title, &article.Body)
//	checkError(err)
//	tmpl, _ := template.ParseFiles(tmplDir + "articles/create.gohtml")
//	err2 := tmpl.Execute(w, article)
//	checkError(err2)
//}
